package com.usf.jprovider.schema.provider.random.number;

import javax.xml.bind.annotation.XmlAttribute;

import com.usf.jprovider.object.JObjectNode;
import com.usf.jprovider.object.env.Environment;
import com.usf.jprovider.object.type.JInteger;
import com.usf.jprovider.object.type.JType;
import com.usf.jprovider.schema.type.DBInteger;
import com.usf.jprovider.tools.RandomTools;

public final class IntegerRandom extends AbstractNumberRandomProvider{
	
	@XmlAttribute protected int min;
	@XmlAttribute protected int max;
	
	public IntegerRandom() {
		super();
		type = new DBInteger();
	}
	public int getMin() {
		return min;
	}
	public int getMax() {
		return max;
	}
	
	@Override
	public JInteger create(Environment env, JObjectNode node) {
		return new JInteger(RandomTools.randomizeInteger(min, max), type.getFormat());
	}
	@Override
	public boolean checkValue(Environment env, JObjectNode node, JType<?> value) {
		int number = ((JInteger)value).getValue();
		return (number>=min && number<=max);
	}
}
